﻿<UserControl x:Class="YoderZone.Extensions.Options.TaskOptionsControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:controls1="clr-namespace:YoderZone.Extensions.Options.Controls"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:viewModel1="clr-namespace:YoderZone.Extensions.Options.ViewModel"
             xmlns:options="clr-namespace:YoderZone.Extensions.Options"
             d:DataContext="{d:DesignInstance viewModel1:TaskOptions}"
             d:DesignHeight="538"
             d:DesignWidth="514"
             mc:Ignorable="d">
    <UserControl.Resources>
        <viewModel1:ColorToBrushConverter x:Key="ColorToBrushConverter" />


        <SolidColorBrush x:Key="OptionMark.Static.Background"
                         Color="#FFFFFFFF" />
        <SolidColorBrush x:Key="OptionMark.Static.Border"
                         Color="#FF707070" />

        <!--  ++ Style to Disable CheckBox  -->

        <Style x:Key="uselessCheckbox"
               TargetType="{x:Type CheckBox}">
            <Setter Property="Background"
                    Value="{StaticResource OptionMark.Static.Background}" />
            <Setter Property="BorderBrush"
                    Value="{StaticResource OptionMark.Static.Border}" />
            <Setter Property="Foreground"
                    Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
            <Setter Property="BorderThickness"
                    Value="1" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type CheckBox}">
                        <Grid x:Name="templateRoot"
                              Background="Transparent"
                              SnapsToDevicePixels="True">
                            <Border x:Name="checkBoxBorder"
                                    Margin="1"
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}">
                                <Grid x:Name="markGrid">
                                    <Path x:Name="optionMark"
                                          Margin="2,1,1,1"
                                          Data="M 1,3 C1,3 1,6 1,6 1,6 4,9 4,9 4,9 9,3 9,3 9,3 9,0 9,0 9,0 4,6 4,6 4,6 1,3 1,3 z"
                                          Fill="{TemplateBinding TextElement.Foreground}"
                                          Opacity="0"
                                          Stretch="Uniform" />
                                </Grid>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked"
                                     Value="true">
                                <Setter TargetName="optionMark"
                                        Property="Opacity"
                                        Value="1" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <viewModel1:BooleanToFontWeightConverter x:Key="BooleanToFontWeightConverter" />
    </UserControl.Resources>

    <!--  !++ Layout Root  -->

    <DockPanel LastChildFill="False"
               SnapsToDevicePixels="True">
        <TextBlock DockPanel.Dock="Top"
                   FontFamily="Times New Roman"
                   FontSize="24pt"
                   FontWeight="Bold"
                   Text="Remarker Tasks" />
        <TextBlock DockPanel.Dock="Top"
                   TextWrapping="Wrap">
            Use the settings on this page to configure a task's name, color, and weight. Task
            names should be unique, but this is not enforced. (Duplicates other than the first
            are ignored.) Up to ten tasks can be defined. Blank task names will be ignored.
        </TextBlock>
        <GroupBox Margin="0,4,0,0"
                  DockPanel.Dock="Top">
            <GroupBox.Header>
                <Label FontWeight="Bold">Selected Task Format Sample</Label>
            </GroupBox.Header>
            <Border Height="80"
                    Background="White"
                    BorderBrush="Black"
                    BorderThickness="1">
                <TextBlock Margin="12"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           FontFamily="{Binding SelectedFont,
                                                FallbackValue=Times New Roman,
                                                TargetNullValue=Times New Roman}"
                           FontSize="48"
                           FontWeight="{Binding SelectedFontWeight,
                                                FallbackValue=Bold,
                                                Converter={StaticResource BooleanToFontWeightConverter}}"
                           Foreground="{Binding SelectedColor,
                                                Converter={StaticResource ColorToBrushConverter},
                                                FallbackValue=Blue}"
                           Text="{Binding SelectedName,
                                          FallbackValue=No name,
                                          TargetNullValue=No name}" />
            </Border>
        </GroupBox>
        <GroupBox Margin="0,4,0,0"
                  DockPanel.Dock="Top"
                  Padding="0,4,0,0">
            <GroupBox.Header>
                <Label Content="Task Options"
                       FontWeight="Bold" />
            </GroupBox.Header>

            <!--  Note: Task Options DataGrid  -->

            <DataGrid x:Name="dataGrid"
                      Height="260"
                      AutoGenerateColumns="False"
                      BeginningEdit="DataGrid_BeginningEdit"
                      CanUserAddRows="False"
                      CanUserDeleteRows="False"
                      CanUserResizeRows="False"
                      CanUserSortColumns="False"
                      CellEditEnding="DataGrid_CellEditEnding"
                      EnableRowVirtualization="False"
                      IsTabStop="True"
                      ItemsSource="{Binding Tasks}"
                      SelectedItem="{Binding SelectedTask}"
                      SelectionMode="Single">
                <DataGrid.Columns>

                    <!--  !+ Name Column  -->
                    <DataGridTemplateColumn MinWidth="150"
                                            CanUserSort="False"
                                            Header="Task Name">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock VerticalAlignment="Top"
                                           Text="{Binding Name}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <controls1:TextBoxFix HorizontalAlignment="Stretch"
                                                      VerticalAlignment="Stretch"
                                                      VerticalContentAlignment="Top"
                                                      Text="{Binding Name,
                                                                     UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                    </DataGridTemplateColumn>

                    <!--  !+ Font Weight Column  -->
                    <DataGridTemplateColumn x:Name="boldColumn"
                                            CanUserSort="False">
                        <DataGridTemplateColumn.Header>Bold</DataGridTemplateColumn.Header>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <CheckBox Margin="0,1,0,0"
                                              HorizontalAlignment="Center"
                                              VerticalAlignment="Top"
                                              IsChecked="{Binding IsBold}"
                                              IsEnabled="False"
                                              Style="{DynamicResource uselessCheckbox}" />
                                </Grid>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <Grid>
                                    <CheckBox Margin="0,1,0,0"
                                              HorizontalAlignment="Center"
                                              VerticalAlignment="Top"
                                              IsChecked="{Binding IsBold,
                                                                  UpdateSourceTrigger=PropertyChanged}" />
                                </Grid>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                    </DataGridTemplateColumn>

                    <!--  !+ Color Selection Column  -->
                    <DataGridTemplateColumn x:Name="colorColumn"
                                            Width="39"
                                            CanUserResize="False"
                                            ClipboardContentBinding="{x:Null}"
                                            Header="Color">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Border Width="13"
                                        Height="13"
                                        Margin="11,1,0,0"
                                        HorizontalAlignment="Left"
                                        VerticalAlignment="Top"
                                        Background="{Binding Color,
                                                             Converter={StaticResource ColorToBrushConverter}}"
                                        BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"
                                        BorderThickness="1" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>

                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <controls1:ColorPicker Width="300"
                                                       Margin="4,2"
                                                       ClipToBounds="True"
                                                       ColorSwath="{Binding Color,
                                                                            Mode=TwoWay,
                                                                            UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>

                    </DataGridTemplateColumn>

                    <!--  !+ Font Selection Column  -->
                    <DataGridTemplateColumn MinWidth="150"
                                            CanUserSort="False"
                                            Header="Font">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Margin="2,0"
                                           Text="{Binding Typeface}"
                                           d:DataContext="{d:DesignInstance viewModel1:TaskAttributes}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <ComboBox ItemsSource="{Binding DataContext.FontNames,
                                                                RelativeSource={RelativeSource FindAncestor,
                                                                                               AncestorType={x:Type DataGrid}}}"
                                          SelectedItem="{Binding Typeface,
                                                                 UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>
        </GroupBox>
        <TextBlock HorizontalAlignment="Center"
                   DockPanel.Dock="Top"
                   Text="{Binding Version,
                                  RelativeSource={RelativeSource FindAncestor,
                                                                 AncestorType=options:TaskOptionsControl}}" />
    </DockPanel>
</UserControl>
